// pages/index_search/index_search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchContent: '',
    content: '',
    historycontent:[],
    teacherlist: [],
    heartcontextlist:[],
    heartmarklist:[],
    reqresplist:[],
    title1: '',
    visible:'visible',
    visible1:'hidden',
    visibleteacher:'hidden',
    visibleheart:'hidden',
    title2:'',
    title3:'',
    title4:'',
    title5:''
  },
  getsearch(res) {
    this.setData({
      content: res.detail.value
    })
    let that = this;
    if (this.data.content != '') {
      that.setData({
        title1: '心理专家',
        visible:'hidden',
        visible1:'visible',
        title2:'查看全部',
        title3:'心理文章',
        title4:'心理测评',
        title5:'提问问答'
            })
      //心理专家
      wx.request({
        url: 'http://localhost:8080/teacherSearch/getTeacherSearch',
        data: {
          teacherName: this.data.content
        },
        success(res) {
          console.log(res.data.data);
          that.setData({
            teacherlist: res.data.data
          })
        }
      })
      // 心理文章
      wx.request({
        url: 'http://localhost:8080/article/findLikeArticle',
        data:{
          articleName:this.data.content
        },
        success(res){
          console.log(res.data.data);
          that.setData({
            heartcontextlist: res.data.data
          })
        }
      })

      // 心理测评
      wx.request({
        url: 'http://localhost:8080/heartmark/getLikeMark',
        data:{
          markName:this.data.content
        },
        success(res){
          console.log(res.data.data);
          that.setData({
            heartmarklist: res.data.data
          })
        }
      })

      // 心理测评
      wx.request({
        url: 'http://localhost:8080/Coursereply/getLikeRR',
        data:{
          userName:this.data.content
        },
        success(res){
          console.log(res.data.data);
          that.setData({
            reqresplist: res.data.data
          })
        }
      })
    }else if(this.data.content==''){
      that.setData({
        title1: '',
        teacherlist:'',
        heartcontextlist:'',
        heartmarklist:'',
        reqresplist:'',
        visible:'visible',
        visible1:'hidden',
        title2:'',
        title3:'',
        title4:'',
        title5:''
      })
    }
  },
  savehistorycontent(res){
    console.log(res);
    let val = res.detail.value
    console.log(val);
    console.log(this.data.historycontent);
    var history = wx.getStorageSync('historycontent') || [];
    console.log(history);
    history.unshift(val);
    console.log(history);
    wx.setStorageSync('historycontent',history)
    console.log(this.data.historycontent);
  },
  clearHis(){
    this.setData({
      historycontent:''
    })
  },


  toIndex() {
    wx.navigateBack()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let history = wx.getStorageSync('historycontent') || []
    this.setData({
      historycontent:history
    })
    console.log(this.data.historycontent);
    wx.removeStorageSync('historycontent')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})